package com.yunhe.abnormal.controller.base;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.base.AlarmScopeDTO;
import com.yunhe.abnormal.service.base.AlarmScopeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 异常适用范围Controller
 * @author liuronglei
 */
@Api(value = "alarmScope", description = "异常适用范围", tags = {"Base_AlarmScope"})
@RestController
@RequestMapping("/alarmScopes")
public class AlarmScopeController {
    @Autowired
    private AlarmScopeService alarmScopeService;

    /**
     * 根据价格类型ID获得价格类型
     * @param id 价格类型ID
     */
    @ApiOperation("根据价格类型ID获得价格类型")
    @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> get(@PathVariable("id") Long id) {
        AlarmScopeDTO alarmScope = alarmScopeService.findById(id);
        return new ResponseEntity<>(new ResultObject<>(alarmScope), HttpStatus.OK);
    }

    /**
     * 根据name获得异常适用范围
     * @param name 异常适用范围name
     */
    @ApiOperation("根据name获得异常适用范围")
    @ApiImplicitParam(name = "name", value = "异常适用范围name", required = true, dataType = "string", paramType = "query")
    @RequestMapping(value = "/byName", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> get(@RequestParam("name") String name) {
        AlarmScopeDTO alarmScope = alarmScopeService.findByName(name);
        return new ResponseEntity<>(new ResultObject<>(alarmScope), HttpStatus.OK);
    }

    /**
     * 根据条件获得异常适用范围列表
     */
    @ApiOperation("根据条件获得异常适用范围列表")
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<ResultObject> search() {
        Iterable<AlarmScopeDTO> results = alarmScopeService.findAll();
        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
    }
}
